#! /usr/bin/env bash

set -euo pipefail

:;     PKG=nz.ac.massey.groupproject.ecs2
:; PKGPATH=nz/ac/massey/groupproject/ecs2
:; VERBOSE=${VERBOSE:-}    # env var.   should be '' or '-v'

function say-phase() {   [[ $VERBOSE = -v ]] && echo;   printf '=== %s\n' "$1";   }

:                                                      && mkdir -pv          .class/"$PKGPATH"
say-phase $"Clearing old class files"                  && rm    -rf $VERBOSE .class/"$PKGPATH"/**.class
say-phase $"Clearing old copy of source files"         && rm    -rf $VERBOSE .class/"$PKGPATH"/*
say-phase $"Copying source files into tempdir"         && cp    -a  $VERBOSE  *.java    .class/"$PKGPATH"
echo

:                                                      && cd .class
say-phase $"Compiling"                                 && javac -Xlint:deprecation "$PKGPATH"/Main.java
say-phase $"Launching"                                 && java -enableassertions "$PKG".Main
